<tr>
  <th>Account</th>
  <th>Share</th>
  <th>Quantity</th>
  <th>Outcome / Avg Price</th>
  <th>Brokerage</th>
  <th>Income / Avg Price</th>
  <th>Balance</th>
  <th>&nbsp;</th>
</tr>
<tr class="main_operation" valign="top">
  <td><%= group.account.name %></td>
  <td><a href="#" onclick="Element.toggle('groupDetails<%= group.id %>')"><%= group.share.code %></a></td>
  <td><%= group.quantity %></td>
  <td><%= sprintf("%0.2f", group.outcome) %> / <%= sprintf("%0.2f", group.averagePurchasePrice) %></td>
  <td><%= sprintf("%0.2f", group.brokerage) %></td>
  <td><%= sprintf("%0.2f", group.income) %> / <%= sprintf("%0.2f", group.averageSalePrice) %></td>
  <td class="<%= totalColor group.balance %>"><%= sprintf("%0.2f", group.balance) %></td>
  <td>
    <select name="newoperation" onchange="if (this.value != 0) { document.location='/operation/newoperation?groupId=<%= group.id %>&amp;operationId=' + this.value; };">
      <% for item in OperationType.group %>
      <option value="<%= item.id %>"><%= item.name %></option>
      <% end %>
    </select>
  </td>
</tr>

<% for subgroup in group.subgroups %>
<tr class="main_operation" valign="top">
  <td colspan="2"><%= subgroup.share.code %></td>
  <td><%= subgroup.quantity %></td>
  <td><%= sprintf("%0.2f", subgroup.outcome) %> / <%= sprintf("%0.2f", subgroup.averagePurchasePrice) %></td>
  <td><%= sprintf("%0.2f", subgroup.brokerage) %></td>
  <td><%= sprintf("%0.2f", subgroup.income) %> / <%= sprintf("%0.2f", subgroup.averageSalePrice) %></td>
  <td class="<%= totalColor subgroup.balance %>"><%= sprintf("%0.2f", subgroup.balance) %></td>
  <td>
    <select name="newoperation" onchange="if (this.value != 0) { document.location='/operation/newoperation?subgroupId=<%= subgroup.id %>&amp;groupId=<%= group.id %>&amp;right=true&amp;operationId=' + this.value; };">
      <% for item in OperationType.right %>
      <option value="<%= item.id %>"><%= item.name %></option>
      <% end %>
    </select>
  </td>
</tr>
<% end %>

  <script lang="JavaScript">
  <!--
  <%= remote_function(
  :update   => "currentValue_#{group.id}",
  :url      => {:action => :currentValue, :params => {:id => group.id}}) %>
  //-->
  </script>
  <tr id="currentValue_<%= group.id %>" >
    <%= render "index/currentValue" %>
  </tr>


<tr valign="top">
  <td colspan="8">
    <div id="groupDetails<%= group.id %>" class="group_details" style="display:display;">
      <table>
        <tbody>
          <tr>
            <th class="group_details">Operation Type</th>
            <th>Share</th>
            <th>Date/Time</th>
            <th>Quantity</th>
            <th>Price</th>
            <th>Amount</th>
            <th>Brokerage</th>
            <th>Total</th>
          </tr>
          <% for operation in group.allOperations %>
          <tr>
            <td><%= operation.operation_type.name %></td>
            <td><%= operation.share.code %></td>
            <td><%= operation.timestamp.strftime("%d.%m.%Y %I:%M %p") %></td>
            <% if operation.split? %>
            <td><%= operation.comment %></td>
            <td colspan="4">&nbsp;</td>
            <% elsif  operation.rightToAcquire? %>
            <td><%= operation.quantity %> <%= operation.comment %></td>
            <td colspan="4">&nbsp;</td>
            <% else %>
            <td><%= operation.quantity %></td>
            <td><%= sprintf("%0.2f", operation.price) %></td>
            <td><%= sprintf("%0.2f", operation.net_amount) %></td>
            <td><%= sprintf("%0.2f", operation.brokerage) %></td>
            <td><%= sprintf("%0.2f", operation.gross_amount) %></td>
            <% end %>
          </tr>
          <% end %>

        </tbody>
      </table>
    </div>
  </td>
</tr>

<tr valign="top">
  <td colspan="8">&nbsp;</td>
</tr>

